import request from '@/utils/request'

const apiName = 'admin/user'

export default {

  getPageList(userQuery) {
    return request({
      url: `${apiName}/list`,
      method: 'post',
      data: userQuery
    })
  },
  getById(id) {
    return request({
      url: `${apiName}/get/${id}`,
      method: 'get'
    })
  },

  save(user) {
    return request({
      url: `${apiName}/save`,
      method: 'post',
      data: user
    })
  },

  updateById(user) {
    return request({
      url: `${apiName}/update`,
      method: 'put',
      data: user
    })
  },
  updatePwdOrStatus(user) {
    return request({
      url: `${apiName}/update-pwd-status`,
      method: 'put',
      data: user
    })
  },
  updateStatus(id, status) {
    let user = {
      id: id,
      status: status
    };
    return this.updatePwdOrStatus(user);
  },
  updatePwdById(id, pwd) {
    let user = {
      id: id,
      password: pwd
    };
    return this.updatePwdOrStatus(user);
  },
  saveAssign(userId, roleId) {
    return request({
      url: `${apiName}/Assign-role`,
      method: 'post',
      params: {userId, roleId}
    })
  },
  removeById(id) {
    return request({
      url: `${apiName}/remove/${id}`,
      method: 'delete'
    })
  },
  batchRemove(idList) {
    return request({
      url: `${apiName}/batchRemove`,
      method: 'delete',
      data: idList
    })
  },
  exportUser(user) {
    return request({
      url: `${apiName}/export`,
      method: 'post',
      data: user
    })
  },
  updateUserPwd(oldPwd,newPwd){
    let params = {
      newPassword: newPwd,
      oldPassword: oldPwd
    };
    return request({
      url: `${apiName}/update-pwd`,
      method: 'put',
      params
    })
  },
  getUserProfile(){
    return request({
      url: `${apiName}/get/profile`,
      method: 'get'
    })
  }
}
